<%@page import="java.net.URLEncoder"%>
<%@page import="java.util.Locale"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="java.util.List"%>
<%@page import="models.ProfitDetail"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%
	List<ProfitDetail> list = (List<ProfitDetail>)request.getAttribute("result");	
	NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
	String fromDate = "";
	String toDate = "";	
	if(request.getAttribute("fromDate")!=null&&!request.getAttribute("fromDate").toString().isEmpty()){
		fromDate = (String)request.getAttribute("fromDate");		
	}
	if(request.getAttribute("toDate")!=null&&!request.getAttribute("toDate").toString().isEmpty()){
		toDate = (String)request.getAttribute("toDate");		
	}

%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>

<script type="text/javascript" src="/admin/js/sale_profit.js"></script>

<script type="text/javascript">
	jQuery(document).ready(function () {		
		jQuery("#fromDate, #toDate" ).datepicker();	
	});
	var server = "<%=UrlHelper.getServerUrl(request)%>";
</script>

        <div class="maincontent noright">
        	<div class="maincontentinner">
            	
                <ul class="maintabmenu">
                	<li><a href="/admin/sales/profit">Báo cáo doanh số</a></li>
                	<li class="current"><a href="/admin/sales/profit-detail">Báo cáo doanh số chi tiết</a></li>
                	<li><a href="/admin/sales/profit-by-saler">Báo cáo bán hàng theo Saler</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">                
					<form class="stdform" action="/admin/sales/profit-detail" method="post">
                    	<div class="one_half">                          	
	                        <p>
	                    		<label>Từ ngày : </label>
	                             <span class="field"><input type="text" name="fromDate" class="longinput" id="fromDate" value="<%=(fromDate!=null&&!fromDate.isEmpty())?fromDate:""%>"/></span>                            
	                    	</p>   
	                    	<p>
	                    		<label>Đến ngày : </label>
	                             <span class="field"><input type="text" name="toDate" class="longinput" id="toDate" value="<%=(toDate!=null&&!toDate.isEmpty())?toDate:""%>"/></span>                            
	                    	</p>                      	
	                    	<p class="stdformbutton">
	                        	<input type="submit" class="reset radius2" value="Tìm kiếm">
	                            <input type="reset" class="reset radius2" value="Làm lại">
	                        </p>                 	     	                    	        	                                         	
                    	</div><!--one_half-->                                                        	                    	       	                        					
                   </form> 
                   <br clear="all" /><br />                	
                	<div class="contenttitle radiusbottom0">
	                	<h2 class="table"><span>Kết quả tìm kiếm</span></h2>
	                </div>	                	           
	                <table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">	                   
	                    <thead>
	                        <tr>	                        	
	                            <th class="head1">STT</th>
	                            <th class="head0">Deal Id</th>
	                            <th class="head1">Tên Deal</th>	                            
	                            <th class="head0">Ngày bắt đầu Deal</th>
	                            <th class="head1">Ngày kết thúc</th>
	                            <th class="head0">Số lượng bán</th>
	                            <th class="head1">Giá nhập</th>
	                            <th class="head0">Giá bán</th>
	                            <th class="head1">Tổng thu dự tính</th>
	                            <th class="head1">Tổng thu tiền mặt</th>
	                            <th class="head0">Tổng thu chuyển khoản</th>				                                                  
	                            <th class="head1">Tổng thực thu</th>
	                        </tr>
	                    </thead>	                   
	                    <tbody>	
	                    <%
	                    	if(list!=null&&list.size()>0){
	                    		for(int i = 0; i< list.size();i++){
	                    %>                    	
	                        <tr>	                        	
								<td class="center"><%=i+1%></td>
	                            <td class="center"><%=list.get(i).getDealId()%></td>
	                            <td class="left"><%=list.get(i).getDealName()%></td>	                            
	                            <td class="center"><%=list.get(i).getDealStartDate()%></td>
	                            <td class="center"><%=list.get(i).getDealEndDate()%></td>
	                            <td class="center"><%=list.get(i).getOrderQuantity()%></td>
	                            <td class="center"><%=nf.format(list.get(i).getImportPrice())%></td>
	                            <td class="center"><%=nf.format(list.get(i).getSellPrice())%></td>
	                            <td class="center"><%=nf.format(list.get(i).getDisplayMoney())%></td>    
	                            <td class="center"><%=nf.format(list.get(i).getRealMoney())%></td>
	                            <td class="center"><%=nf.format(list.get(i).getBankTransferMoney())%></td>
	                            <td class="center"><%=nf.format(list.get(i).getTotalMoney())%></td>                       
	                        </tr>	 
                        <%
	                    		}
                    		}
                        %>                     
	                    </tbody>
	                </table>	
	                <div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate">
	                	<% String url = URLEncoder.encode((String) UrlHelper.getServerUrl(request) + "/sales-profit-detail-file?fromDate=" + fromDate + "&toDate=" + toDate + "&action=toFile"); %>
	                 	<a class="paginate_button" target="blank" href="/export-excel?url=<%=url%>">Xuất File Excel</a>	                	
	                </div>                  	                	             
                </div><!--content-->                
            </div><!--maincontentinner-->            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>            
        </div><!--maincontent-->        
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>